/*
 * @Author: wangjq4214
 * @Date: 2022-04-17 09:41:02
 * @LastEditTime: 2022-06-05 16:58:27
 * @LastEditors: wangjq4214
 */
package main

import (
	"flag"
	"log"
)

var (
	task = flag.String("task", "", "The task file path")
	addr = flag.String("addr", "localhost:50052", "The address to connect to")

	cpu      = flag.Int("cpu", 2, "CPU requirements for task, invalid when task option is specified.")
	storage  = flag.Int("storage", 70, "Storage requirements for task, invalid when task option is specified.")
	taskTime = flag.Int("time", 5, "Time requirements for task, invalid when task option is specified.")
	need     = flag.Bool("need", false, "Invalid when task option is specified.")
	dataID   = flag.Int("data-id", 2, "Data ID requirements for task, invalid when task option is specified.")
	dataIP   = flag.String("data-ip", "localhost:50052", "Data IP requirements for task, invalid when task option is specified.")
)

func main() {
	flag.Parse()
	commiter, err := NewTaskCommit(*addr)
	if err != nil {
		log.Printf("Init commiter error: %v", err.Error())
	}

	if *task != "" {
		err := commiter.CommitByFile(*task)
		if err != nil {
			log.Printf("Commit task error: %v", err.Error())
		}

		return
	}

	err = commiter.CommitByCmd(*cpu, *storage, *taskTime, *need, *dataID, *dataIP)
	if err != nil {
		log.Printf("Commit task error: %v", err.Error())
	}
}
